#include "EventHandler.h"

EventHandler::EventHandler(std::weak_ptr<Subscriber> subscriber)
:_subscriber(subscriber)
{
}

EventHandler::~EventHandler()
{
}

void EventHandler::set_callback(std::function<void(Event &)> callback, unsigned int priority)
{
    _callback = callback;
    _priority = priority;
}

void EventHandler::operator()(Event &event)const
{
    if (auto sub = _subscriber.lock() && _callback)
    {
        _callback(event);
    }
}

bool EventHandler::is_valid() const
{
    return !_subscriber.expired();
}

void EventHandler::set_priority(unsigned int priority)
{
    _priority = priority;
}

bool EventHandler::operator<(const EventHandler &other) const
{
    return _priority < other._priority;
}
